package io.renren.modules.workmanagement.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import io.renren.common.utils.PageUtils;
import io.renren.common.utils.Query;
import io.renren.modules.workmanagement.dao.WorkFinishStatusDetailDao;
import io.renren.modules.workmanagement.entity.WorkFinishStatusDetailEntity;
import io.renren.modules.workmanagement.service.WorkFinishStatusDetailService;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;


@Service("workFinishStatusDetailService")
public class WorkFinishStatusDetailServiceImpl extends ServiceImpl<WorkFinishStatusDetailDao, WorkFinishStatusDetailEntity> implements WorkFinishStatusDetailService {

    @Override
    public PageUtils queryPage(Map<String, Object> params) {
        IPage<WorkFinishStatusDetailEntity> page = this.page(
                new Query<WorkFinishStatusDetailEntity>().getPage(params),
                new QueryWrapper<WorkFinishStatusDetailEntity>()
        );

        return new PageUtils(page);
    }

    @Override
    public WorkFinishStatusDetailEntity getByWorkIdAndUserId(Long workId, Long userId) {
        return this.lambdaQuery().eq(WorkFinishStatusDetailEntity::getWorkId, workId).eq(WorkFinishStatusDetailEntity::getStudentId, userId).one();
    }

    @Override
    public List<WorkFinishStatusDetailEntity> listByWorkIds(List<Long> workIds) {
        return this.lambdaQuery().in(WorkFinishStatusDetailEntity::getWorkId, workIds).list();
    }

    @Override
    public List<WorkFinishStatusDetailEntity> getByWorkIdAndUserIds(Long workId, List<Long> studentIds) {
        return this.lambdaQuery().eq(WorkFinishStatusDetailEntity::getWorkId, workId).in(WorkFinishStatusDetailEntity::getStudentId, studentIds).list();
    }

    @Override
    public List<WorkFinishStatusDetailEntity> getByWorkIdsAndUserId(List<Long> workIds, Long userId) {
        return this.lambdaQuery().in(WorkFinishStatusDetailEntity::getWorkId, workIds).eq(WorkFinishStatusDetailEntity::getStudentId, userId).list();
    }

}
